unit oConversionManager;

interface

uses
  oManager, oProcessItem, oProcessObjectConstants, SysUtils;

type
  EConversionManager = class(Exception)
  end;

  TConversionManager = class(TManager)
    public
      constructor create(paMaster: TManager);
      function ProcessObject(paItem: TProcessItem):TProcessItem; override; final;
  end;

implementation

uses
  oGeneratorData, uOSPRand, oProcessObjects, uOSPDyn;

resourcestring eConvManNotValidType = 'not valid type';

{ TConversionManager }

constructor TConversionManager.create(paMaster: TManager);
begin
  inherited create(paMaster);
end;

function TConversionManager.ProcessObject(paItem: TProcessItem): TProcessItem;
var generator: tRndm;
begin
  result := nil;
  generator := nil;
  case paItem.Code of

    CONVERT_DATA_TO_GENERATOR:
    begin
      if not(paItem.Data is TProcessingGeneratorData) then raise EConversionManager.Create(eConvManNotValidType);
      if (paItem.Data as TProcessingGeneratorData).Data <> nil then
      case (paItem.Data as TProcessingGeneratorData).Data.Code of

        genGamma:
          with ((paItem.Data as TProcessingGeneratorData).Data as TGammaGeneratorData) do
            generator := tGama.Create(Mean,Dispersion,MinX,MaxX,Randomized);

        genBeta:
          with ((paItem.Data as TProcessingGeneratorData).Data as TBetaGeneratorData) do
            generator := tBeta.Create(Mean,Dispersion,MinX,MaxX,Randomized);

        genBinomial:
          with ((paItem.Data as TProcessingGeneratorData).Data as TBinomialGeneratorData) do
            generator := tBinomial.Create(Number,Probab,Randomized);

        genDiscrete:
          with ((paItem.Data as TProcessingGeneratorData).Data as TDiscreteGeneratorData) do
            generator := tDiscrete.Create(Probs,Values,Randomized);

        genErlang:
          with ((paItem.Data as TProcessingGeneratorData).Data as TErlangGeneratorData) do
            generator := tErlang.Create(Mean,Dispersion,Randomized);

        genExponential:
          with ((paItem.Data as TProcessingGeneratorData).Data as TExponentialGeneratorData) do
            generator := tExponential.Create(Mean,Randomized);

        genLinear:
          with ((paItem.Data as TProcessingGeneratorData).Data as TLinearGeneratorData) do
            generator := tLinear.Create(Probs,Values,Randomized);

        genNormal:
          with ((paItem.Data as TProcessingGeneratorData).Data as TNormalGeneratorData) do
            generator := tNormal.Create(Mean,Dispersion,Randomized);

        genPoisson:
          with ((paItem.Data as TProcessingGeneratorData).Data as TPoissonGeneratorData) do
            generator := tPoisson.Create(Mean,Randomized);

        genUniform:
          with ((paItem.Data as TProcessingGeneratorData).Data as TUniformGeneratorData) do
            generator := tUniform.Create(From,UniTo,Randomized);

      end;
      result := TProcessItem.create(PO_SUCCESS,TprocessingGenerator.Create(generator));
    end;

  end;
  paItem.Free;
end;

end.
